/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-03-05 06:56:51
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2024-03-05 14:07:04
 * @FilePath: \vue3tsh:\study\clound\vite-template\electron\main.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { BrowserWindow, app } from "electron";
import path from "path";
const isDev = process.env.NODE_ENV === "development";
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";

import config from "../package.json";
/**
 * @description: 创建窗口
 */
function createWindow() {
	const mainWindow = new BrowserWindow({
		height: 800,
		useContentSize: true,
		width: 1200,
		frame: true,
		resizable: true,
		skipTaskbar: false,
		transparent: false,
		title: config.name,
		icon: path.join(__dirname, "../public/favicon.ico"),
		autoHideMenuBar: true,
		x: 0,
		y: 0,
		webPreferences: {
			nodeIntegration: true,
			contextIsolation: false,
			webSecurity: false,
			preload: path.join(__dirname, "preload.js")
		}
	});

	if (isDev) {
		mainWindow.loadURL("http://localhost:3000");
		// 打开开发者工具
		mainWindow.webContents.openDevTools();
	} else {
		mainWindow.loadFile(path.join(__dirname, "../dist/index.html"));
	}
}

app.whenReady().then(() => {
	createWindow();

	app.on("activate", function () {
		if (BrowserWindow.getAllWindows().length === 0) createWindow();
	});
});

app.on("window-all-closed", function () {
	if (process.platform !== "darwin") app.quit();
});
